package com.fu.controller;


import javax.servlet.http.HttpServletRequest;

import com.fu.response.RestResult;
import com.fu.utils.RestResultUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.fu.service.UserService;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * 
 * @ClassName: ApiController
 * @Description: API相关的控制类
 * @author Little Ant
 * @date 2017年10月31日上午11:40:06
 */
@RestController
@RequestMapping("/api/v1.0/")
public class ApiController {
	@Autowired
	private UserService userService;

	@PostMapping("/auth/token")
	@ApiOperation(value = "获取token", notes = "输入应用名和密码获取token")
	@ApiImplicitParams({ @ApiImplicitParam(name = "appId", value = "应用明", required = true, dataType = "String"),
			@ApiImplicitParam(name = "secretKey", value = "密码", required = true, dataType = "String") })
	public RestResult getToken(@RequestParam String appId, @RequestParam String secretKey) {
		return RestResultUtils.genSuccessResult(this.userService.getToken(appId, secretKey));
	}


	@PostMapping("/auth/token/reflesh")
	@ApiOperation(value = "刷新token", notes = "刷新token")
	@ApiImplicitParams({
			@ApiImplicitParam(name="timestamp",value = "时间戳",required = true,dataType = "String"),
			@ApiImplicitParam(name="token",value = "token令牌",required = true,dataType = "String"),
			@ApiImplicitParam(name="sign",value = "接口参数签名",required = true,dataType = "String")
	})
	public String refreshToken(HttpServletRequest request){
		String token = request.getParameter("token");
		return this.userService.updateToken(token);
	}
}
